package com.jack.payment.constant.enums;

import com.jack.payment.constant.ResultHintConstant;
import com.jack.payment.entity.common.BusinessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public enum PaymentStatusEnum {
    WAIT_PAY(0),            // 待支付
    PAY(1),                 // 已支付
    PAY_SUCCESS(2),         // 已支付, 处理成功
    WAIT_REFUND(3),         // 待退款, 退款中
    REFUND_SUCCESS(4)       // 退款成功
    ;
    private Integer stat;

    private static Logger log = LoggerFactory.getLogger(PaymentStatusEnum.class);

    PaymentStatusEnum(Integer stat) {
        this.stat = stat;
    }

    public Integer getStat() {
        return stat;
    }

    public static PaymentStatusEnum getPaymentStatusEnum(Integer index) throws BusinessException {
        Integer length = PaymentStatusEnum.values().length;
        if (index > length) {
            log.error("支付状态获取枚举下标越界{}, 确保获取下标小于{}", index, length);
            throw new BusinessException(ResultHintConstant.ENUM_ERROR);
        }
        return PaymentStatusEnum.values()[index];
    }
}
